package com.itheima.bookservice;

import com.itheima.bookdao.BaseBookDao;
import com.itheima.bookdao.Book2Dao;
import com.itheima.bookdao.BookDao;
import com.itheima.bookdao.BookFileDao;
import com.itheima.domain.Book;
import com.itheima.factory.BookDaoFactory;

public class BookService {
    private BaseBookDao dao = BookDaoFactory.getBookDao();

    public boolean isExitsBook(String bookId) {

        Book[] books = dao.getAllBooks();

        for (int i = 0; i < books.length; i++) {
            Book bookArray = books[i];
            if(bookArray != null){
                if(bookArray.getBookId().equals(bookId)){
                    return true;
                }
            }
        }

        return false;

    }

    public boolean addBook(Book book) {

        boolean result = dao.addBook(book);
        return result;

    }

    public void deleteBook(String bookId) {
        dao.deleteBook(bookId);
    }

    public void updateBook(Book book) {
        dao.updateBook(book);
    }

    public Book[] getAllBooks() {
        Book[] books = dao.getAllBooks();
        return books;
    }
}
